//
//  DingDanDetailGoodsTableViewCell.m
//  Experss
//
//  Created by wmwMAC on 17/8/4.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "DingDanDetailGoodsTableViewCell.h"

#import "DingDanTableCollectionViewCell.h"


@interface DingDanDetailGoodsTableViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource>

{
    NSArray *dataAray2;
}
@end


@implementation DingDanDetailGoodsTableViewCell






- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
//        self.imageArray = [NSArray array];
//        self.imageArray = @[@"",@"",@"",@"",@"",@""];
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 200, 47)];
    label.text = @"胡来超市";
    label.textAlignment = NSTextAlignmentLeft;
    label.textColor = [UIColor blackColor];
    label.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:label];
    self.titleLabel = label;
    
    UILabel *typeLable = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth-80, 0, 70, 47)];
    typeLable.text = @"待送货";
    typeLable.textAlignment = NSTextAlignmentRight;
    typeLable.textColor = BaseBlueColor;
    typeLable.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:typeLable];
    self.stateLabel = typeLable;
    
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumInteritemSpacing = 7;
    layout.minimumLineSpacing = 7;
    layout.sectionInset = UIEdgeInsetsMake(26, 15, 6, 25);
    CGFloat width = (kScreen_Width - 40 - 30 - 40)/5.0;
    layout.itemSize = CGSizeMake(width, width);
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 47, kScreen_Width-40, width + 26+6 +0.01) collectionViewLayout:layout];
    collectionView.backgroundColor = [UIColor whiteColor];
    collectionView.showsVerticalScrollIndicator = NO;
    collectionView.showsHorizontalScrollIndicator = NO;
    collectionView.bounces = NO;
    collectionView.scrollEnabled = NO;
    [collectionView registerClass:[DingDanTableCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    collectionView.delegate = self;
    collectionView.dataSource = self;
    self.collectionView = collectionView;
    [self.contentView addSubview:collectionView];
//    self.collectionView.userInteractionEnabled = NO;
    
    UIImageView *imgV = [BasePublicCreatUI createImageViewFrame:CGRectMake(kScreen_Width-40, 47 + 26 + (width-30)/2.0, 30, 30) imageName:@"tijiaodingdan_dian" color:[UIColor whiteColor]];
    imgV.contentMode = UIViewContentModeScaleAspectFit;
    self.moreImageView = imgV;
    [self.contentView addSubview:imgV];
    imgV.userInteractionEnabled = YES;
    [imgV addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(KongImgViewClicked:)]];;
    
        
    
    UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(self.collectionView.frame), SCREEN_WIDTH-30, 40)];
    label3.text = @"¥399.0 共7件，重量2.5kg";
    label3.textAlignment = NSTextAlignmentLeft;
    label3.textColor = [UIColor lightGrayColor];
    label3.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:label3];
    
    self.priceLabel = label3;
    
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 47, SCREEN_WIDTH, 1)];
    lineView.backgroundColor = RGBAColor(240, 240, 240, 1);
    
    [self.contentView addSubview:lineView];

    UIView *lineView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 47 + (kScreen_Width - 40 - 30 - 40)/5.0 + 26+6 + 40-1, SCREEN_WIDTH, 1)];
    lineView2.backgroundColor = RGBAColor(240, 240, 240, 10);
    
    [self.contentView addSubview:lineView2];
    
}

-(void)KongImgViewClicked:(UITapGestureRecognizer *)tap{
    // 商品明细
    
    if ([self.delegate respondsToSelector:@selector(DingDanDetailGoodsImgCellClicked)]) {
        
        [self.delegate DingDanDetailGoodsImgCellClicked];
        
    }

}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.imageArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    DingDanTableCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.imgV.backgroundColor = [UIColor cyanColor];
    
    [cell.imgV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",self.imageArray[indexPath.item]]] placeholderImage:[UIImage imageNamed:@"quetu"]];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    // 商品明细
    
    if ([self.delegate respondsToSelector:@selector(DingDanDetailGoodsImgCellClicked)]) {
        
        [self.delegate DingDanDetailGoodsImgCellClicked];
        
    }
    
    
}




- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)dianjiDataArray:(NSArray *)dataAray {
    dataAray2 = dataAray;
}

@end
